import db from 'utils/localstorage'
import Cookies from 'js-cookie'
export default {
  namespaced: true,
  state: {
    token: Cookies.get('token'),
    expireTime: db.get('EXPIRE_TIME'),
    user: (Cookies.get('userInfo')&&JSON.parse(Cookies.get('userInfo'))),
    permissions: db.get('PERMISSIONS'),
    roles: db.get('ROLES')
  },
  mutations: {
    setToken (state, val) {
      db.save('token', val)
      state.token = val
    },
    setExpireTime (state, val) {
      db.save('EXPIRE_TIME', val)
      state.expireTime = val
    },
    setUser (state, val) {
      db.save('userInfo', val)
      state.user = val
    },
    setPermissions (state, val) {
      db.save('PERMISSIONS', val)
      state.permissions = val
    },
    setRoles (state, val) {
      db.save('ROLES', val)
      state.roles = val
    }
  }
}
